// pages/articleDetail/articleDetail.js
const ArticleHttp = require("../../models/AticleHttp")
Page({
  data: {
    item:"",
    title:""
  },
  onLoad:async function (options) {
    var {id} = options;
    var result = await ArticleHttp.getDetail(id);
    var {msg,res} = result.data;
    // console.log(result)
    wx.setNavigationBarTitle({
      title: msg
    })
    this.setData({
      item:res[0],
      title:msg
    })
  },
  //监听收藏状态
  async handleCollect(){
    var item = this.data.item;
    var {_id,collected} = item;
    console.log(_id,collected)
    if(collected){
      item.collected = false;
      await ArticleHttp.setCollect({id:_id,collected:false})
    }else{
      item.collected = true;
      await ArticleHttp.setCollect({id:_id,collected:true})
    }
    this.setData({item})
  }
})